const defaults = {}
import Vue from 'vue'
import resultVue from './result.vue'

const ResultConstructor = Vue.extend(resultVue)

let instance

const defaultCallback = action => {}

let initInstance = () => {
  instance = new ResultConstructor({
    el: document.createElement('div')
  })
  instance.callback = defaultCallback
}

const Result = function (options, callback) {
  if (!instance) {
    initInstance();
  }
  instance.visible = true
  let anchor = document.querySelector(options.anchor)
  anchor.appendChild(instance.$el);

  Vue.nextTick(() => {
    instance.visible = true;
  });
}

Result.close = () => {
  if (instance) {
    instance.doClose()
    instance.visible = false
  }
}

export default Result
export {
  Result
}